#include <iostream>
#include "base/include.h"

#include "pnoise.h"

int main()
{
    ///specular lighting failure is probably due to rotated normals;

    ///find some way to remove kernel part 3
    ///huehuehue
    ///do depth buffer swapping for speed (no non asynchronous clearing)
    obj_manager *objs=new obj_manager;

    object *loaded=parse_obj("untitled.obj", ".png");//spring4.obj");
    ///must be trianglated and have normals exported
    loaded->texture_load();
    objs->add_obj(loaded);

    //std::cout << loaded->texname;

    //object *terrain=new object;

    //noise_obj(terrain, 100, 100, 999, 999);


    //terrain->texture_load();

    //objs->add_obj(terrain);

    Engine engine;


    oclstuff();
    engine.init_glcl();


    engine.load(1024, 768, 700, false); ///dimensions - x, y, z, FULLSCREEN
    ///performance quickly degrades with screen size due to the screen filling operation
    ///nope, opengl


    engine.c_pos.z=-24; ///starting camera position. Completely arbitrary, but designed to give a reasonably full shot of object as a reliable performance benchmark
    engine.c_pos.x=50;
    engine.c_pos.y=-24;
    engine.c_pos.z=45;

    engine.c_rot.x=-M_PI/2.0;


    int mult=100;
    ///position of light, colour of light. Yes, this needs to be much improved, but currently a useful stopgap measure
    ///light circles.


    cl_float4 l4= {50, 20, 45, 4000},
    //cl_float4 l4= {180, 0, 0, 200},
              c4= {255, 0, 0}; ///Hmm. Coloured lights vs non colored lights



    //for(int i=0; i<100; i++)
    engine.add_light(l4, c4);




    //cl_float4 l7={-3, -2, -10, 150},
     //c7={255, 50, 50};
     ///lights illuminate colours rather than giving them off


     /*for(int i=0; i<=100; i++){

        for(int j=0; j<=100; j++){
            if(i%10==0 && j%10==0){
                cl_float4 l={i, 12, j, 60};
                cl_float4 c={128, 128, 128};
                //engine.add_light(l, c);
            }
        }
     }*/

   // engine.add_light(l7, c7);
    //engine.add_light(l7, c7);


    //exit(1);
    //boost::thread thread(boost::bind(&obj_manager::push_objects, objs)); ///have this fired by obj->push

    objs->push_objects();


    //thread.join();
    //std::cout << "hi" << std::endl;
    ///texture is causing shit to crash handle in memory manager al,so store the number of triangles for every object being passed so we know which texture goes where, OR pass super texture and adjust coordinates based on actual size on texture, though opencl might not like that so IONO
    engine.set_ambiance(255.0f, 255.0f, 255.0f, 0.3f); // change this to ambient colour
    //exit(1);
    while(engine.window.IsOpened())
    {



        engine.tick();

    }


    clReleaseKernel(cl::kernel);
    clReleaseProgram(cl::program);
    clReleaseCommandQueue(cl::cqueue);
    clReleaseContext(cl::context);



    return 0;
}
